/**
  ETFRoot project, Anyang Normal University && IMP-CAS

  \class ETFHPTDCChannel
  \brief the class holding the timing data acquired by the HPTDC (@CERN) chip
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-09-27
  \date 2021-10-10 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-09-27   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFHPTDCChannel_h
#define ETFHPTDCChannel_h

#include <vector>
#include "ETFRawChannel.h"

using std::vector;

class ETFHPTDCChannel : public ETFRawChannel{
public:
  ETFHPTDCChannel();
  ETFHPTDCChannel(const ETFHPTDCChannel &ch);
  virtual ~ETFHPTDCChannel();

  ///@{ getters
  double GetLeadingEdge(int i = 0) const;
  double GetTrailingEdge(int i = 0) const;
  const vector<double> &GetLeadingEdges() const{ return vl; }
  const vector<double> &GetTrailingEdges() const{ return vt; }
  int GetNofLeadingEdges() const{ return vl.size(); }
  int GetNofTrailingEdges() const{ return vt.size(); }
  double GetTOT(int i = 0) const{ return GetTrailingEdge(i) - GetLeadingEdge(i); }
  bool IsVeryHighResolution() const{ return fIs_V; }
  ///@}

  ///@{ setters
  virtual void AddLeadingEdgeV(int l);
  virtual void AddLeadingEdgeH(int l);
  virtual void AddTrailingEdgeV(int t);
  virtual void AddTrailingEdgeH(int t);
  virtual void SetIsVeryHighResolution(bool is_V){ fIs_V = is_V; }
  ///@}

  virtual void Reset();
  virtual void Initialize();
  virtual void Print() const;

  friend class ETFPXIUnpacker;

  ClassDef(ETFHPTDCChannel, 1); // timing data acquired by HPTDC (@CERN) chip

  /// time for one channel of HPTDC HIGH resolution mode: ~100ps
  static const double kH_BLIP; //! '//!' means don't save this to file
  /// time for one channel of HPTDC VERY HIGH resolution mode: ~25ps
  static const double kV_BLIP; //!

  friend class ETFDetectorManager;

protected:
  virtual void AddLed(double l); ///< add a leading edge
  virtual void AddTed(double t); ///< add a trailing edge
  virtual void SubtractTrigger(unsigned bunchID); ///< intended to subtract trigger time
  /// \note that a channel can either be a VERY HIGH resolution HPTDC channel or
  ///  a HIGH resolution HPTDC channel
  vector<double> vl, vt;
  bool fIs_V; ///< if the channel is of very high resolution or high resolution
};

#endif
